<?php
/**
 * File : ModelLogin.php
 * Created by Ludovic Reenaers
 * Created on  20 oct. 2010
 * lreenaers@hotmail.com
 */
class ModelLogin extends Model{
	function remind(){
		$usrdao = $this->daoFactory->getUserDAO();
		$usr = $usrdao->getByEmail($_POST['email']);
		try{
			if(!is_a($usr, 'User') && $usr->isActive()){
				throw new FieldFormatException($this->translator->userUnknown);
			}else{
				$to  = $_POST['email'] ;
				$subject = $this->translator->hereispws;
				$message = '<html><head><title>'.$subject.'</title></head><body>';
				$message .= $this->translator->youasked;
				$hash = md5($usr->getEmail().$usr->getPwsHash());
				$message .= '<br/><a href="'.$_SESSION['config']->siteurl.$_SESSION['config']->controler.'?/user/reset/'.$to.'/'.$hash.'/">'.$this->translator->clickhere.'</a><br/>';
				$message .= '</body></html>';
				$headers  = 'MIME-Version: 1.0' . "\r\n";
				$headers .= 'Content-type: text/html; charset='.$_SESSION['encoding']. "\r\n";
				$headers .= 'Reply-To: webmaster@example.com' . "\r\n";
				$headers .= 'X-Mailer: PHP/' . phpversion(). "\r\n";
				$headers .= 'To: '.$usr->getName().', '.$usr->getSurname().' <'.$to.'>' . "\r\n";
				$headers .= "X-Priority: 1 (Higuest)\n";
				$headers .= "X-MSMail-Priority: High\n";
				$headers .= "Importance: High\n";
				$headers .= 'From: Administrateur <'.$_SESSION['config']->info.'>' . "\r\n";
				mail($to, $subject, $message, $headers);
			}
		}	catch(Exception $e){
			$this->addFormError($e);
		}
		return $this->hasFormError();
	}
	function show(){
		$this->startFormSession();
		if(!isset($_SESSION['failedlogin'])){
			$_SESSION['failedlogin']=0;
		}
		$generator = new LoginFormGenerator($this->translator,$this->params,$this->daoFactory);
		$generator->addChild(new ThirdFailureCaptchaGenerator($this->translator,$this->params,$this->daoFactory));
		return $generator;
	}
	function forgot(){
		
		$this->startFormSession();
		$generator = new ForgotFormGenerator($this->translator,$this->params,$this->daoFactory);
		return $generator;
	}
}
?>